<template>
  <a-spin :spinning="spinning" tip="加载中...">
    <a-card :bordered="false">
      <h3 style="margin-bottom: 20px;">{{ !pageId ? '新增' : '编辑' }}抽奖活动</h3>
      <a-steps :current="1" size="small" style="width: 800px;margin: 20px 0 30px;">
        <a-step title="基础信息" />
        <a-step title="抽奖设置" />
        <a-step title="分享信息" />
      </a-steps>
      <a-row type="flex">
        <a-col flex="360px">
          <div class="page">
            <div class="container" :style="`backgroundImage: url(${form.backPicture});`">
              <!-- <div class="rule icon-wrapper">
                <div class="icon"></div>
                <div class="t">活动规则</div>
              </div>
              <div class="award icon-wrapper">
                <div class="icon"></div>
                <div class="t">我的奖品</div>
              </div>
              <div class="opportunity icon-wrapper">
                <div class="icon"></div>
                <div class="t">获取机会</div>
              </div> -->
              <header class="title">{{ form.titleName }}</header>
              <img :src="form.titlePicture" alt="主题海报图" class="banner" />
              <div class="notice" v-if="form.isBroadcast">159****9999抽中100元优惠券</div>
              <div class="content" :style="`background: ${form.backColor};`">
                <div class="item" :style="`backgroundImage: url(${form.prizeList[0].awardPicture})`" >
                  <template v-if="!form.prizeList[0].awardPicture">奖品图1</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[1].awardPicture})`" >
                  <template v-if="!form.prizeList[1].awardPicture">奖品图2</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[2].awardPicture})`" >
                  <template v-if="!form.prizeList[2].awardPicture">奖品图3</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[7].awardPicture})`" >
                  <template v-if="!form.prizeList[7].awardPicture">奖品图8</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.buttonPicture})`" >
                  <template v-if="!form.buttonPicture">抽奖按钮图</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[3].awardPicture})`" >
                  <template v-if="!form.prizeList[3].awardPicture">奖品图4</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[6].awardPicture})`" >
                  <template v-if="!form.prizeList[6].awardPicture">奖品图7</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[5].awardPicture})`" >
                  <template v-if="!form.prizeList[5].awardPicture">奖品图6</template>
                </div>
                <div class="item" :style="`backgroundImage: url(${form.prizeList[4].awardPicture})`" >
                  <template v-if="!form.prizeList[4].awardPicture">奖品图5</template>
                </div>
              </div>
              <div class="num">剩余10次抽奖机会</div>
            </div>
          </div>
        </a-col>
        <a-col flex="auto" style="width: 0;">
          <a-form-model ref="rulesForm" :model="form" :rules="rules" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
            <a-tabs v-model="pageActiveKey">
              <a-tab-pane tab="页面设置" key="1">
                <a-form-model-item label="抽奖页标题" prop="titleName">
                  <a-input :maxLength="8" v-model="form.titleName" allowClear placeholder="最多输入8个字" />
                </a-form-model-item>
                <a-form-model-item label="主题海报图" prop="titlePicture">
                  <JImageUpload :uploadParams="getUploadParams()" :isMove="false" :fileSize="1" :number="1" :accept="'image/*'" @fileChange="fileTitlePictureChange" v-model="titlePictureList"></JImageUpload>
                  <div class="des">750x300px或者等比例图片，支持jpg、PNG、GIF格式，图片大小建议小于500k</div>
                </a-form-model-item>
                <a-form-model-item label="抽奖背景图" prop="backPicture">
                  <JImageUpload
                    :uploadParams="getUploadParams()"
                    :isMove="false"
                    :fileSize="1"
                    :number="1"
                    :accept="'image/*'"
                    @fileChange="fileBackPictureChange"
                    v-model="backPictureList"
                  ></JImageUpload>
                  <div class="des">750x1660px或者等比例图片，支持jpg、PNG、GIF格式，图片大小建议小于500k</div>
                </a-form-model-item>
                <a-form-model-item label="抽奖按钮图" prop="buttonPicture">
                  <JImageUpload :uploadParams="getUploadParams()" :isMove="false" :fileSize="1" :number="1" :accept="'image/*'" @fileChange="fileButtonPictureChange" v-model="buttonPictureList"></JImageUpload>
                  <div class="des">300x300px或者等比例图片，支持jpg、PNG、GIF格式，图片大小建议小于500k</div>
                </a-form-model-item>
                <a-form-model-item label="宫格背景色" prop="backColor">
                  <a-input v-model="form.backColor" type="color" style="width:100px"></a-input>
                </a-form-model-item>
                <a-form-model-item label="活动规则" prop="rule">
                  <a-textarea v-model.trim="form.rule" :maxLength="ruleLimit" placeholder="" :rows="8" allowClear />
                  <div style="text-align: right;margin-top: -15px;">{{ `${ruleNumber}/${ruleLimit}` }}</div>
                </a-form-model-item>
                <a-form-model-item label="中奖播报" prop="isBroadcast">
                  <a-switch v-model="form.isBroadcast" />
                </a-form-model-item>
              </a-tab-pane>
              <a-tab-pane tab="奖品设置" key="2">
                <div class="tab-wrapper">
                  <div class="tab-content">
                    <a-tabs v-model="activeKey" hide-add type="editable-card"  @edit="onEdit">
                      <a-tab-pane v-for="(pane, index) in form.panes" :key="pane.key" :tab="`奖品${index + 1}`" :closable="form.panes.length > 1">
                        <a-form-model-item label="奖品名称" :prop="`panes.${index}.awardName`" :rules="rules.awardName">
                          <a-input :maxLength="8" v-model="pane.awardName" allowClear placeholder="最多输入8个字" />
                        </a-form-model-item>
                        <a-form-model-item label="奖品类型" :prop="`panes.${index}.awardType`" :rules="rules.awardType">
                          <a-select v-model="pane.awardType" style="width: 100%;" show-search :filter-option="filterOption">
                            <a-select-option :value="item.id" v-for="item in typeList" :key="item.id">{{ item.name }}</a-select-option>
                          </a-select>
                        </a-form-model-item>
                        <a-form-model-item v-if="pane.awardType == 2" key="ruleId" label="优惠券awardID" :prop="`panes.${index}.ruleId`" :rules="rules.ruleId">
                          <a-input v-model="pane.ruleId" allowClear placeholder="请填写券awardID，多张券使用英文逗号,隔开" />
                        </a-form-model-item>
                        <a-form-model-item v-if="pane.awardType == 3" key="productSpu" label="商品条码" :prop="`panes.${index}.productSpu`" :rules="rules.productSpu">
                          <a-input v-model="pane.productSpu" allowClear placeholder="请输入商品条码" />
                        </a-form-model-item>
                        <a-form-model-item v-if="pane.awardType == 1" key="giveIntegral" label="赠送积分" :prop="`panes.${index}.giveIntegral`" :rules="rules.giveIntegral">
                          <a-input-number v-model.trim="pane.giveIntegral" allowClear :min="0" style="width: 300px;" /> 积分
                        </a-form-model-item>
                        <a-form-model-item v-if="pane.awardType != 0" label="奖品份数" :prop="`panes.${index}.awardNum`" :rules="rules.awardNum">
                          <a-input-number v-model.trim="pane.awardNum" :min="0" style="width: 300px;" /> 份
                        </a-form-model-item>
                        <a-form-model-item label="奖品图" :prop="`panes.${index}.awardPicture`" :rules="rules.awardPicture">
                          <JImageUpload
                            :uploadParams="getUploadParams()"
                            :isMove="false"
                            :fileSize="1"
                            :number="1"
                            :accept="'image/*'"
                            @fileChange="fileAwardPictureChange(arguments, index)"
                            v-model="awardPictureObj[pane.key]"
                          ></JImageUpload>
                          <div class="des">300x300px或者等比例图片，支持jpg、PNG、GIF格式，图片大小建议小于500k</div>
                        </a-form-model-item>
                      </a-tab-pane>
                    </a-tabs>
                  </div>
                  <a-button :disabled="form.panes.length > 7" class="add" type="primary" @click="hanelAdd" icon="plus"></a-button>
                </div>
                <a-form-model-item label="中奖规则" required>
                  <a-table bordered :pagination="false" :columns="columns" :data-source="form.prizeList" :rowKey="(record, index) => index" size="middle">
                    <span slot="customPercentageTitle">中奖概率<br />(<span :class="totalPercent > 100 ? 'red' : ''">{{totalPercent}}%</span>)</span>
                    <span slot="prize" slot-scope="text, record, index">
                      <a-form-model-item :prop="`prizeList.${index}.key2`" :rules="rules.key2">
                        <a-select v-model="record.key2" style="width: 200px;" @change="prizeChange(arguments, index)" show-search :filter-option="filterOption">
                          <a-select-option :value="item.key" v-for="item in form.panes.filter(e => e.awardName)" :key="item.key">{{ item.awardName }}</a-select-option>
                        </a-select>
                      </a-form-model-item>
                    </span>
                    <span slot="percentage" slot-scope="text, record, index">
                      <a-form-model-item :prop="`prizeList.${index}.awardProbability`" :rules="rules.awardProbability">
                        <a-input-number v-model.trim="record.awardProbability" :min="0" :max="100" style="width: 100px;" />
                        %
                      </a-form-model-item>
                    </span>
                  </a-table>
                </a-form-model-item>
              </a-tab-pane>
            </a-tabs>
            <a-form-model-item :labelCol="{ span: 4 }" :wrapperCol="{ span: 18 }">
              <a-button style="margin-right: 10px;" @click="handleBack">上一步</a-button>
              <a-button @click="handleSubmit" type="primary">下一步</a-button>
            </a-form-model-item>
          </a-form-model>
        </a-col>
      </a-row>
    </a-card>
  </a-spin>
</template>
<script>
import Vue from 'vue'
import JImageUpload from '../../components/JImageUpload.vue'
// import { create, all, isArray } from 'mathjs'
const math = require('mathjs')
import { saveOrUpdatePageInfo, getLuckyDrawPageByPageId } from '@/api/marketingCenter/luckyDraw'
// const config = {
//     epsilon: 1e-12,
//     matrix: 'Matrix',
//     number: 'BigNumber', // 可选值：number BigNumber
//     precision: 64,
//     predictable: false,
//     randomSeed: null
// }
// const math = create(all, config)
const panes = [
  { 
    id: null,
    awardCount: null,
    title: '奖品1', 
    awardName: '', 
    awardType: '', 
    awardNum: '', 
    giveIntegral: '', 
    awardPicture: '',
    key: '0',
    ruleId: '',
    productSpu: ''
}]

const columns = [
  {
    title: '序号',
    align: 'center',
    customRender: (text, record, index) => `${index + 1}`
  },
  {
    title: '奖品',
    align: 'center',
    scopedSlots: { customRender: 'prize' }
  },
  {
    slots: { title: 'customPercentageTitle' },
    align: 'center',
    scopedSlots: { customRender: 'percentage' }
  }
]
const prizeListData = [
  {
    id: null,
    productId: null,
    awardCount: null,
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null, 
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,    
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,   
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,   
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,    
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,   
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  },
  {
    id: null,
    productId: null,
    awardCount: null,   
    key2: '',
    awardProbability: 0,
    awardPicture: ''
  }
]
const ruleInteger = [
  { required: true, message: '请输入', trigger: 'blur' },
  {
    validator: (rule, value, callback) => {
      const reg = /^[0-9]*[1-9][0-9]*$/
      if (!value) {
        callback()
      } else {
        if (reg.test(value)) {
          callback()
        } else {
          return callback(new Error('请输入正确的格式'))
        }
      }
    },
    trigger: 'blur'
  }
]
export default {
  components: {
    JImageUpload
  },
  data() {
    return {
      ruleLimit: 500,
      ruleNumber: 0,
      columns,
      awardPictureObj: {},
      activeKey: '0',
      typeList: [//1积分,2优惠券,3实物,0谢谢参与
        {
          name: '积分',
          id: '1'
        },
        {
          name: '优惠券',
          id: '2'
        },
        {
          name: '实物',
          id: '3'
        },
        {
          name: '谢谢参与',
          id: '0'
        }
      ],
      newTabIndex: 1,
      buttonPictureList: [],
      backPictureList: [],
      titlePictureList: [],
      imgList: [],
      photoshopVisible: false,
      pageActiveKey: '1',
      id: this.$route.params.id,
      pageId: this.$route.query.pageId || null,
      shareId: null,
      spinning: false,
      form: {
        rule: '',
        prizeList: prizeListData,
        panes,
        isBroadcast: true,
        titleName: '抽奖活动',
        buttonPicture: '',
        backPicture: '',
        titlePicture: '',
        backColor: '#327542'
      },
      rules: {
        backColor: [{ required: true, message: '请输入', trigger: 'blur' }],
        isBroadcast: [{ required: true, message: '请选择', trigger: 'change' }],
        titleName: [{ required: true, message: '请输入', trigger: 'blur' }],
        rule: [{ required: true, message: '请输入', trigger: 'blur' }],
        awardName: [{ required: true, message: '请输入', trigger: 'blur' }],
        awardType: [{ required: true, message: '请选择', trigger: 'change' }],
        awardNum: ruleInteger,
        giveIntegral: ruleInteger,
        awardPicture: [{ required: true, message: '请选择', trigger: 'change' }],
        titlePicture: [{ required: true, message: '请选择', trigger: 'change' }],
        buttonPicture: [{ required: true, message: '请选择', trigger: 'change' }],
        backPicture: [{ required: true, message: '请选择', trigger: 'change' }],
        ruleId: [
          { required: true, message: '请输入', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const reg = /^\d+(,\d+)*$/
              if (!value) {
                callback()
              } else {
                if (reg.test(value)) {
                  callback()
                } else {
                  return callback(new Error('请输入正确的格式'))
                }
              }
            },
            trigger: 'blur'
          }
        ],
        productSpu: [{ required: true, message: '请输入', trigger: 'blur' }],
        key2: [{ required: true, message: '请选择', trigger: 'change' }],
        awardProbability: [
          { required: true, message: '请输入', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const reg = /((^[1-9]\d*)|^0)(\.\d{0,4}){0,1}$/
              if (!value) {
                callback()
              } else {
                if (reg.test(value)) {
                  callback()
                } else {
                  return callback(new Error('请输入正确的格式'))
                }
              }
            },
            trigger: 'blur'
          }
        ]
      }
    }
  },
  watch: {
    'form.panes': {
      handler:function(cur,old){
       console.log(cur, 'curcur')
        this.form.prizeList.forEach((e, index) => {
          cur.forEach(i => {
            if (e.key2 == i.key) {
              Vue.set(this.form.prizeList, index, {
                ...e,
                ...i,
                id: e.id
              })
            }
          })
        })
      },
      deep:true
    },
    form: {
      handler: function () {
        const _this = this
        _this.ruleNumber = _this.form.rule.length
      },
      deep: true
    }
  },
  created() {
    this.getDetails()
  },
  activated() {
  },
  computed: {
    totalPercent() {
      const list = this.form.prizeList.map(e => e.awardProbability).filter(i => i > 0)
      const total = list.reduce((a, b) => {
        return this.add(a, b)
      }, 0)
      return total
    }
  },
  mounted() {},
  methods: {
    // 加法
    add(a,b){
      return math.add(math.bignumber(a), math.bignumber(b));
    },
    prizeChange(v, index) {
      const { panes, prizeList} = this.form
      const filterList = panes.filter(e => e.key == v[0])
      prizeList[index].awardPicture = filterList.length ? filterList[0].awardPicture : ''
    },
    resetDetails() {
      const panes = [
          {
            id: null,
            awardCount: null,
            title: '奖品1', 
            awardName: '', 
            awardType: '', 
            awardNum: '', 
            giveIntegral: '', 
            awardPicture: '',
            key: '0',
            ruleId: '',
            productSpu: ''
        }]
      const prizeListData = [
        {
          id: null,
          productId: null,
          awardCount: null,
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,   
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,    
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,    
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,    
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,    
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,  
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        },
        {
          id: null,
          productId: null,
          awardCount: null,    
          key2: '',
          awardProbability: 0,
          awardPicture: ''
        }
      ]
      this.form.panes = panes
      this.form.prizeList = prizeListData
    },
    // 获取详情
    getDetails() {
      if (!this.pageId || this.pageId == -1) {
        this.resetDetails()
        return
      }
      const data = {
        pageId: this.pageId,
        luckyId: this.id
      }
      getLuckyDrawPageByPageId(data)
      .then(res => {
        if (res.code === 200) {
          const { 
            buttonPicture,
            backPicture,
            titlePicture,
            isBroadcast,
            luckyDrawDetailList,
            luckyDrawProductList,
            shareId
          } = res.data
          this.shareId = shareId ? shareId : null
          // let filterLuckyDrawDetailList = []
          // luckyDrawDetailList.forEach(e => {
          //   if (!filterLuckyDrawDetailList.find(i => i.key == e.key)) {
          //     filterLuckyDrawDetailList.push(e)
          //   }
          // })
          luckyDrawProductList.forEach(e => {
            if (e.awardPicture) {
              this.awardPictureObj[e.key] = [e.awardPicture]
            } else {
              this.awardPictureObj[e.key] = []
            }
          })
         
          // const currentPanes = filterLuckyDrawDetailList.map((e, index) => {
          //   return {
          //     key: e.key + '',
          //     title: `奖品${index+1}`,
          //     awardType: e.awardType + '',
          //     awardPicture: e.awardPicture,
          //     giveIntegral: e.giveIntegral,
          //     awardNum: e.awardNum,
          //     awardName: e.awardName,
          //     ruleId: e.ruleId,
          //     productSpu: e.productSpu
          //   }
          // })
          const currentPanes = luckyDrawProductList.map((e, index) => {
            return {
              ...e,
              key: e.key + '',
              title: `奖品${index+1}`,
              awardType: e.awardType + ''
            }
          })
          const currentPanesIds = currentPanes.map(e => e.key).sort((a,b)=>{return a-b})
          console.log(currentPanesIds, 'currentPanesIds')
          this.newTabIndex = currentPanes.length ? Number(currentPanesIds[currentPanesIds.length -1]) +1 : 1
          console.log(this.newTabIndex, 'newTabIndex')
          this.activeKey = currentPanes.length ? currentPanes[0].key + '' : '0'
          console.log(luckyDrawDetailList, 'luckyDrawDetailList')
          this.form = {
            ...res.data,
            isBroadcast: isBroadcast == 1 ? false : true,
            panes: currentPanes,
            prizeList: luckyDrawDetailList.length ? luckyDrawDetailList.map(e => {
              return {
                ...e,
                key2: e.key || e.key === 0 ? e.key + '' : '',
                awardType: e.awardType + ''
              }
            }).concat(...prizeListData).slice(0, 8) : prizeListData
          }
          console.log(this.form, 'this.form')
          this.buttonPictureList = buttonPicture ? buttonPicture.split(',') : []
          this.backPictureList = backPicture ? backPicture.split(',') : []
          this.titlePictureList = titlePicture ? titlePicture.split(',') : []
        } else {
          this.$message.error(res.msg || res.message)
        }
      })
      .catch(err => {})
    },

    // 新增奖品
    hanelAdd() {
      if (this.form.panes.length > 7) return
      const activeKey = `${this.newTabIndex++}`
      this.form.panes.push({
        id: null,
        awardCount: null,
        awardName: '',
        awardType: '',
        awardNum: '',
        giveIntegral: '',
        awardPicture: '',
        key: activeKey,
        ruleId: '',
        productSpu: ''
      })
      this.activeKey = activeKey
    },

    // 删除奖品
    onEdit(targetKey, action) {
      const panes = this.form.panes
      if (panes.length < 2) return
      this[action](targetKey)
    },

    // 删除奖品
    remove(targetKey) {
      const prizeList = this.form.prizeList.filter( e => e.key2).map(e => e.key2)
      console.log(prizeList, 'prizeList', targetKey)
      if (prizeList.includes(targetKey)) {
        this.$message.info('不可删除已关联的奖品！')
        return
      }
      let activeKey = this.activeKey
      let lastIndex
      this.form.panes.forEach((pane, i) => {
        if (pane.key === targetKey) {
          lastIndex = i - 1
        }
      })
      const panes = this.form.panes.filter(pane => pane.key !== targetKey)
      if (panes.length && activeKey === targetKey) {
        if (lastIndex >= 0) {
          activeKey = panes[lastIndex].key
        } else {
          activeKey = panes[0].key
        }
      }
      this.form.panes = panes
      this.activeKey = activeKey
    },

    getUploadParams() {
      return {
        actionUrl: 'https://jic.jnby.com/activity/market-act/common/upload/multipart',
        headers: {
          authorization: 'authorization-text'
        },
        uploadHost: 'https://img.bzhz.jnbygroup.com/'
      }
    },

    fileTitlePictureChange(list) {
      this.form.titlePicture = list.length ? list[0].url : ''
      this.$refs.rulesForm.validateField(["titlePicture"])
    },

    fileBackPictureChange(list) {
      this.form.backPicture = list.length ? list[0].url : ''
      this.$refs.rulesForm.validateField(["backPicture"])
    },

    fileButtonPictureChange(list) {
      this.form.buttonPicture = list.length ? list[0].url : ''
      this.$refs.rulesForm.validateField(["buttonPicture"])
    },

    fileAwardPictureChange(list, index) {
      this.form.panes[index].awardPicture = list.length && list[0][0] ? list[0][0].url : ''
      this.$refs.rulesForm.validate()
    },

    // 确认
    handleSubmit() {
      this.$refs.rulesForm.validate(valid => {
        if (valid) {
          const { backColor, panes, prizeList, isBroadcast } = this.form
          if (!backColor) {
            this.$message.info('请选择宫格背景色！')
            return
          }
          for (let i = 0; i < panes.length; i++) {
            if (!panes[i].awardName || !panes[i].awardPicture || !panes[i].awardType) {
              this.$message.info('奖品信息未完善！')
              return
            }
          }
          console.log(this.totalPercent, 'this.totalPercent')
          if (this.totalPercent != 100) {
            this.$message.info('中奖概率需为100%，请核对中奖概率！')
            return
          }
          const currentLuckyDrawDetailList = prizeList.map((e, index) => {
            return {
              ...e,
              ...panes.filter(i => i.key == e.key2)[0],
              id: e.id,
              panes: null,
              prizeList: null,
              awardOrder: index + 1,
              pageId: this.$route.query.pageId || null
            }
          })
          const luckyDrawDetailList = currentLuckyDrawDetailList.map(e => {
            return {
              ...e,
              giveIntegral: e.awardType == 1 ? e.giveIntegral : null,
              ruleId: e.awardType == 2 ? e.ruleId : null,
              productSpu: e.awardType == 3 ? e.productSpu : null,
              awardNum: e.awardType == 0 ? null : e.awardNum
            }
          })
          
          const data = {
            ...this.form,
            isBroadcast: isBroadcast ? 0 : 1,
            luckyDrawProductList: panes, 
            luckyDrawDetailList,
            panes: null,
            prizeList: null,
            luckyId: this.id,
            pageId: this.pageId
          }
          this.spinning = true
          saveOrUpdatePageInfo(data).then(res => {
            if (res.code === 200) {
              this.spinning = false
              if (!this.pageId || this.pageId == -1) {
                this.$router.replace(`/marketingCenter/memberPromotions/luckyDraw/addOrEditSetUp/${this.id}?pageId=${res.data}`)
              }
              if (this.shareId && this.shareId != -1) {
                this.$router.push(`/marketingCenter/memberPromotions/luckyDraw/addOrEditShare/${this.id}?pageId=${res.data}&shareId=${this.shareId}`)
              } else {
                this.$router.push(`/marketingCenter/memberPromotions/luckyDraw/addOrEditShare/${this.id}?pageId=${res.data}`)
              }
             
            } else {
              this.spinning = false
              this.$message.error(res.msg || res.message)
            }
          }).catch(err => {
            this.spinning = false
          })
        } else {
          this.$message.info('信息未完善！')
          return false
        }
      })
    },

    //返回
    handleBack() {
      this.$router.go(-1)
    },

    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    }
  }
}
</script>
<style lang="less" scoped>
@margin: 30px;
.color-box {
  border: 1px dashed #999;
  display: inline-block;
  vertical-align: middle;
  width: 100px;
  height: 20px;
  cursor: pointer;
}
.page {
  padding: 10px;
  background: rgb(247, 245, 245);
  width: 320px;
  height: 700px;
  overflow: hidden;
  overflow-y: auto;

  .container {
    position: relative;
    background: #ececec;
    min-height: 100%;
    background-size: 100% 100%;
    background-position: center 40px;
    .icon-wrapper {
      position: absolute;
      right: 2px;
      .icon {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background-color: #999;
      }
      .t {
        font-size: 12px;
      }
      &.rule {
        top: 70px;
      }
      &.award {
        top: 140px;
      }
      &.opportunity {
        bottom: 70px;
      }
    }

    .title {
      height: 40px;
      line-height: 40px;
      text-align: center;
      font-size: 12px;
      color: #333;
      background: #fff;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .banner {
      display: block;
      margin: 40px auto 0;
      width: 260px;
      min-height: 80px;
    }
    .notice {
      padding-left: 20px;
      margin: 10px @margin 0;
      height: 38px;
      line-height: 38px;
      font-size: 12px;
      color: #333;
      background: #dbdbdb;
      border-radius: 5px;
    }

    .content {
      display: flex;
      flex-wrap: wrap;
      padding: 10px;
      background: #dbdbdb;
      margin: 20px @margin 0;
      .item {
        margin: 1%;
        width: 31.333%;
        padding-bottom: 31.333%;
        height: 0;
        text-align: center;
        line-height: 70px;
        font-size: 12px;
        border: 1px solid #999;
        background-color: #fff;
        background-size: 100% 100%;
      }
    }
    .num {
      padding: 0 10px;
      width: 140px;
      margin: 10px auto 0;
      height: 30px;
      line-height: 30px;
      text-align: center;
      font-size: 12px;
      color: #333;
      background: #dbdbdb;
      border-radius: 15px;
    }
  }
}
.des {
  margin-top: -10px;
}
.tab-wrapper {
  position: relative;
  .tab-content {
    margin-right: 25px;
  }
  .add {
    position: absolute;
    right: 0;
    top: 10px;
  }
}
.table-wrapper {
  display: flex;
  align-items: flex-start;
  .title {
    line-height: 40px;
    font-size: 14px;
  }
  .content {
    flex: 1;
  }
}
.red{
  color: red;
}
/deep/.my-img-item {
    margin: 0 8px 8px 0;
}
/deep/ .ant-col-6{
  width: 110px;
}
</style>
